package logic

import (
	"context"
	"shenzhou_srv/models"

	"shenzhou_srv/internal/svc"
	"shenzhou_srv/shenzhou"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *shenzhou.UserListRequest) (*shenzhou.UserListResponse, error) {
	var err error
	var u models.User
	u.Status = int(in.Status)
	userlist, err := u.List()
	if err != nil {
		logx.Error("用户列表展示失败")
		return nil, err
	}

	var userList []*shenzhou.UserList

	for _, user := range userlist {
		list := shenzhou.UserList{
			UserId:   int64(user.ID),
			UserName: user.UserName,
			Sex:      user.Sex,
			Age:      int64(user.Age),
			Address:  user.Address,
			Status:   int64(user.Status),
		}
		userList = append(userList, &list)
	}

	return &shenzhou.UserListResponse{
		List: userList,
	}, nil
}
